package com.xyht.sca_s.student_manage_system.modules.assetFixedIdle.controller;


import com.xyht.sca_s.student_manage_system.auth.util.JwtTokenUtil;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ResponseResult;
import com.xyht.sca_s.student_manage_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.sca_s.student_manage_system.modules.assetFixedIdle.entity.req.SmsAssetFixedIdleApplyAllowReq;
import com.xyht.sca_s.student_manage_system.modules.assetFixedIdle.entity.req.SmsAssetFixedIdleApplyReq;
import com.xyht.sca_s.student_manage_system.modules.assetFixedIdle.service.SmsAssetFixedIdleApplyService;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 资产闲置申请表 前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2024-09-29
 */
@RestController
@RequestMapping("/assetFixedIdle")
@SecretBody
public class SmsAssetFixedIdleApplyController {
    @Resource
    private SmsAssetFixedIdleApplyService smsAssetFixedIdleApplyService;
    @Resource
    private JwtTokenUtil jwtTokenUtil;

    @ApiModelProperty(value = "提交资产处置申请")
    @PostMapping("/add")
    public ResponseResult addFixedIdleApply(@RequestBody @Validated SmsAssetFixedIdleApplyReq req, HttpServletRequest request) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsAssetFixedIdleApplyService.addFixedIdleApply(req, user_id);
    }

    @ApiModelProperty(value = "撤销资产处置申请")
    @PostMapping("/cancel")
    public ResponseResult cancelFixedIdleApply(@RequestBody SmsAssetFixedIdleApplyReq cancelReq, HttpServletRequest request) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsAssetFixedIdleApplyService.cancelFixedIdleApply(cancelReq, user_id);
    }

    @ApiModelProperty(value = "审批")
    @PostMapping("/allow")
    public ResponseResult allowAssetFixedIdleApply(@RequestBody SmsAssetFixedIdleApplyAllowReq allowReq, HttpServletRequest request) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsAssetFixedIdleApplyService.allowAssetFixedIdleApply(allowReq, user_id);
    }

    @ApiModelProperty(value = "审批列表")
    @GetMapping("/list")
    public ResponseResult getAssetFixedIdleApplyList(@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                     @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                     @RequestParam(value = "apply_type") Integer apply_type,
                                                     HttpServletRequest request) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsAssetFixedIdleApplyService.getAssetFixedIdleApplyList(user_id, apply_type, pageNum, pageSize);
    }

    @ApiModelProperty(value = "审批详情")
    @GetMapping("/detail")
    public ResponseResult getAssetFixedIdleApplyDetail(@RequestParam(value = "apply_id") String apply_id,
                                                       HttpServletRequest request) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsAssetFixedIdleApplyService.getAssetFixedIdleApplyDetail(apply_id, user_id);
    }

    @ApiModelProperty(value = "获取所有审批列表")
    @GetMapping("/allList")
    public ResponseResult getAssetFixedIdleApplyAllList(@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                        @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                        @RequestParam(value = "allowStatus", required = false) Integer allowStatus,
                                                        @RequestParam(value = "applyUserName", required = false) String applyUserName) {
        return smsAssetFixedIdleApplyService.getAssetFixedIdleApplyAllList(allowStatus, applyUserName, pageNum, pageSize);
    }

    @ApiModelProperty(value = "获取闲置申请物品详情列表")
    @GetMapping("/goodsList")
    public ResponseResult getIdleAssetGoodsList(@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                @RequestParam(value = "apply_id") String apply_id) {
        return smsAssetFixedIdleApplyService.getIdleAssetGoodsList(apply_id, pageNum, pageSize);
    }
}

